import 'dart:convert';
import 'dart:io';

main() {
  print('开始执行');
  Future(() async {
    String token = await login(username: '蔡法宗', passward: 'cfz211314');
    print('登录成功 token是$token');
    //2.根据token 获取数据
    Map userInfo = await getUserInfo(token: token);
    print('用户信息是$userInfo');
    //3.保存用户数据
    await saveUserInfo(userInfo: userInfo);
    print('保存用户数据成功');
  });
  print('不能阻塞代码');
}

//1.登录成功后保存数据
Future<String> login({required String username, required String passward}) {
  return Future(() {
    sleep(Duration(seconds: 2));
    return 'token_123456';
  });
}

//2.根据token获取用户信息
Future<Map> getUserInfo({required String token}) {
  return Future(() {
    sleep(Duration(seconds: 2));
    return {'username': '张三', 'age': 18};
  });
}

//3.保存用户数据
Future<void> saveUserInfo({required Map userInfo}) {
  return Future(() {
    sleep(Duration(seconds: 2));
    print('保存用户数据成功');
  });
}
